1 =============================================================================
2 LIBRARY APPLICATION : VBClassLibrary Project Overview
3 =============================================================================
5 /////////////////////////////////////////////////////////////////////////////
8 The code sample demonstrates a VB.NET class library that we can use in other
9 applications. The class library exposes a simple class named VBSimpleObject.
15 Instance field and property:
16 Private fField As Single
17 Public Property FloatProperty() As Single
20 Public Overrides Function ToString() As String
22 Shared (static) method:
23 Public Shared Function GetStringLength(ByVal str As String) As Integer
26 ' The event is fired in the set accessor of FloatProperty
27 Public Event FloatPropertyChanging(ByVal NewValue As Single, _
28 ByRef Cancel As Boolean)
31 /////////////////////////////////////////////////////////////////////////////
34 VBReflection -> VBClassLibrary
35 VBReflection dynamically loads the assembly, VBClassLibrary.dll, and
36 instantiate, examine and use its types.
38 VBClassLibrary - CSClassLibrary
39 They are the same class library implemented in different languages.
42 /////////////////////////////////////////////////////////////////////////////
45 A. Creating the project
47 Step1. Create a Visual Basic / Class Library project named VBClassLibrary in
50 B. Adding a class VBSimpleObject to the project and define its fields,
51 properties, methods, and events.
53 Step1. In Solution Explorer, add a new Class item to the project and name it
56 Step2. Edit the file VBSimpleObject.cs to add the fields, properties, methods,
59 C. Signing the assembly with a strong name (Optional)
61 Strong names are required to store shared assemblies in Global Assembly Cache
62 (GAC). This helps avoid DLL Hell. Strong names also protects the assembly
63 from being hacked (replaced or injected). A strong name consists of the
64 assembly's identity—its simple text name, version number, and culture info
65 (if provided)—plus a public key and a digital signature. It is generated
66 from an assembly file using the corresponding private key.
68 Step1. Right-click the project and open its Properties page.
70 Step2. Turn to the Signing tab, and check the Sign the assembly checkbox.
72 Step3. In the Choose a strong name key file drop-down, select New. The
73 "Create Strong Name Key" dialog appears. In the Key file name text box, type
74 the desired key name. If necessary, we can protect the strong name key file
75 with a password. Click the OK button.
78 /////////////////////////////////////////////////////////////////////////////
81 MSDN: Creating Assemblies
82 http://msdn.microsoft.com/en-us/library/b0b8dk77.aspx
84 How to: Sign an Assembly with a Strong Name
85 http://msdn.microsoft.com/en-us/library/xc31ft41.aspx
88 /////////////////////////////////////////////////////////////////////////////